import request from '@/plugins/request';
import apiHost from './apiHost';
import store from '@/store';
import util from '@/libs/util';


const axiosPost = (url, data) => {
    return request({
        url,
        method: 'post',
        data
    });
}
const axiosGet = (url, params) => {
    return request({
        url,
        method: 'get',
        params
    });
}
const systemmanagementPath = apiHost('systemmanagement');
const webPath = apiHost('web');


// 图片验证码路径
export const validateCodeImgURL = `${systemmanagementPath}/systemmanagement/auth/validateCode`

// 登录
export function login(data) {
    return request({
        url: `${systemmanagementPath}/login`,
        method: 'post',
        data
    });
}

// 用户名/邮箱/手机校验
export function checkUser(params) {
    return request({
        url: `${systemmanagementPath}/systemmanagement/user/checkUser`,
        method: 'get', 
        params
    });
}

// 获取手机验证码 (新)
export function getRandomCode(data) {
    return request({
        url: `${systemmanagementPath}/systemmanagement/user/getRandomCode`,
        method: 'post', 
        data
    });
}
// 注册校验手机验证码
export function checkCaptchaCode(params) {
    return request({
        url: `${systemmanagementPath}/systemmanagement/user/checkCaptchaCode`,
        method: 'get', 
        params
    });
}

// //注册 (新)
// export function register(data) {
//     return request({
//         url: `${systemmanagementPath}/systemmanagement/user/register`,
//         method: 'post',
//         data
//     });
// }

//注册 (新) 2020-05-29
export function register(data) {
    return request({
        url: `${systemmanagementPath}/systemmanagement/user/registerUser`,
        method: 'post',
        data
    });
}

//手机号登录 2020-05-29
export function getLoginCode(data) {
    return request({
        url: `${systemmanagementPath}/systemmanagement/user/getLoginCode`,
        method: 'post',
        data
    });
}
//忘记密码页面/修改密码
export function forgotpwd(data) {
    return request({
        url: `${systemmanagementPath}/systemmanagement/user/pwd/forgotpwd`,
        method: 'post',
        data
    });
}
//忘记密码页面/获取验证码

export function getForgotPWDCode(data) {
    return request({
        url: `${systemmanagementPath}/systemmanagement/user/getForgotPWDCode`,
        method: 'post',
        data
    });
}

// ----- 工作台接口
//查询用户注册信息
export const getBUserById = (data) => axiosGet(`${webPath}/web/user/getBUserById`, data)
//查询是否认证
export const hasAuth = (data) => axiosGet(`${webPath}/web/user/hasAuth`, data)
//查询认证信息
export const queryCBaseInfo = (data) => axiosPost(`${webPath}/web/user/queryCBaseInfo`, data)
export const getCBaseInfoByCustNoOrConsNo = (data) => axiosGet(`${webPath}/web/user/getCBaseInfoByCustNoOrConsNo`, data)
//用户认证
export const userAuth = (data) => axiosPost(`${webPath}/web/user/userAuth`, data)
//解除认证
export const removeAuthRela = (data) => axiosGet(`${webPath}/web/user/removeAuthRela`, data)
//查询企业资料信息
export const getEnterpriseInfomation = (data) => axiosGet(`${webPath}/web/user/getEnterpriseInfomation`, data)
//编辑企业资料信息
export const updateEnterpriseInfomation = (data) => axiosPost(`${webPath}/web/user/updateEnterpriseInfomation`, data)
//查询我的需求
export const getEnquiryFormListsByUserId = (data) => axiosPost(`${webPath}/web/user/getEnquiryFormListsByUserId`, data)
//查询需求记录
export const getEnquiryFormListsByQuery = (data) => axiosPost(`${webPath}/web/user/getEnquiryFormListsByQuery`, data)
//提交需求or回复需求
export const saveAdvisory = (data) => axiosPost(`${webPath}/web/user/saveAdvisory`, data)
// 电力考核
export const listAssessmentComps = (data) => axiosPost(`${apiHost('informationBase')}/information/informationPub/elecService/assessmentComp/listAssessmentComps`, data)

// 获取企业信息
export const getBasicUserInfo = (data = {}) => {
    let url = `${apiHost('profile')}/profile/customerView/getCBasicInfoByCustId`;
    let subUser = store.state.admin.subUser.user;
    let token = util.token.initToken();
    if(subUser.custId || subUser.cliqueId || token.custId || token.cliqueId){
        if(subUser.custId || token.custId){
            data.custId = subUser.custId || token.custId;
        }
        if(subUser.cliqueId || token.cliqueId){
            url = `${apiHost('profile')}/profile/myHome/customerArchives/userEnergyArchives/cCliqueInfoManage/getCCliqueInfo/${subUser.cliqueId || token.cliqueId}`;
        }
    }else{

        url = `${apiHost('systemmanagement')}/systemmanagement/auth/getBasicUserInfo`;
    }
    return axiosGet(url, data)
}

// 发布详情
export const getMApplicationInfo = (data) => axiosGet(`${apiHost('panoramahall')}/panoramahall/electricBusiness/getMApplicationInfo`, data)

// 检修计划
export const listOverhaulInfos = (data) => axiosPost(`${apiHost('informationBase')}/information/informationPub/elecService/overhaulInfo/listOverhaulInfos`, data)

//获取公告列表（分页）
export const listAnnouncementForPaging = (data) => axiosPost(`${apiHost('systemmanagement')}/systemmanagement/assistant/announcement/listAnnouncementForPaging`, data)

//获取收藏列表（分页）
// export const listFunctionFavoritesNoPaging = (data) => axiosPost(`${apiHost('systemmanagement')}/systemmanagement/assistant/functionFavorite/listFunctionFavoritesNoPaging`, data)
export const listFavoritedForPaging = (data) => axiosPost(`${apiHost('systemmanagement')}/systemmanagement/assistant/functionFavorite/listFavoritedForPaging`, data)

//取消收藏
export const cancelFunctionFavorite = (data) => axiosPost(`${apiHost('systemmanagement')}/systemmanagement/assistant/functionFavorite/cancelFunctionFavorite`, data)

//收藏
export const confirmFunctionFavorite = (data) => axiosPost(`${apiHost('systemmanagement')}/systemmanagement/assistant/functionFavorite/addFunctionFavorite`, data)

//2.1.5.智慧能源小助手-我的任务
export const listPage = (data) => axiosPost(`${apiHost('operationmanagement')}/operationmanagement/sWorkJob/listPage`, data)

//2.1.6.1.最近使用菜单列表（最近20条）接口
export const listRecentlyUsedForPaging = (data) => axiosPost(`${apiHost('systemmanagement')}/systemmanagement/auth/function/listRecentlyUsedForPaging`, data)

//2.1.3.2.消息列表（分页）接口
export const listMessagesForPaging = (data) => axiosPost(`${apiHost('systemmanagement')}/systemmanagement/message/listMessagesForPaging`, data)


// 获取菜单是否收藏
export function getFunctionIsFavortie(params) {
    return request({
        url: `${systemmanagementPath}/systemmanagement/assistant/functionFavorite/getFunctionIsFavortie`,
        method: 'get', 
        params
    });
}

//2.1.6.2.记录最近使用的菜单
export const insertRecentlyUsed = (data) => axiosPost(`${apiHost('systemmanagement')}/systemmanagement/auth/function/insertRecentlyUsed`, data)

//获取一个随机码
export const getRandomCodeForSMS = (data) => axiosPost(`${apiHost('systemmanagement')}/systemmanagement/user/getRandomCodeForSMS`, data)
